import { Configuration, App } from '@midwayjs/core';
import * as koa from '@midwayjs/koa';
import * as validate from '@midwayjs/validate';
import * as info from '@midwayjs/info';
import * as jwt from '@midwayjs/jwt';
import * as upload from '@midwayjs/upload';
import * as typegoose from '@midwayjs/typegoose';
import * as captcha from '@midwayjs/captcha';
import * as crossDomain from '@midwayjs/cross-domain';
// import * as sequelize from '@midwayjs/sequelize';
// import * as typeorm from '@midwayjs/typeorm';

// import * as redis from '@midwayjs/redis';
// import * as view from '@midwayjs/view-nunjucks';
// import * as swagger from '@midwayjs/swagger';
// import * as bull from '@midwayjs/bull';

import { join } from 'path';
// import { DefaultErrorFilter } from './filter/default.filter';
// import { NotFoundFilter } from './filter/notfound.filter';
// import { ReportMiddleware } from './middleware/report.middleware';
import { WeatherErrorFilter } from './filter/weather.filter';
import { JwtMiddleware } from './middleware/jwt.middleware';



@Configuration({
  imports: [
    koa,
    validate,
    {
      component: info,
      enabledEnvironment: ['local'],
    },
    // swagger,      // 接口UI 
    // view,         // 模板渲染
    // bull,         // 任务队列   未完全学习
    jwt,          // Json Web Token
    upload,       // 文件上传
    // redis,        // 导入 redis 组件
    typegoose,    //  mongoDB 
    captcha,      // 验证码
    crossDomain,  // 跨域
    // typeorm,          // 加载 typeorm 组件
    // sequelize,
  ],
  importConfigs: [join(__dirname, './config')],
})
export class ContainerLifeCycle {
  @App()
  app: koa.Application;

  // @Inject()
  // bullFramework: bull.Framework;

  async onReady() {
    // add middleware
    this.app.useMiddleware([JwtMiddleware]);
    // add filter
    // this.app.useFilter([NotFoundFilter, DefaultErrorFilter]);
    this.app.useFilter([WeatherErrorFilter]);
  }

  async onServerReady() {
    // // 获取 Processor 相关的队列
    // const testQueue = this.bullFramework.getQueue('test');
    // // 立即执行这个任务
    // const job = await testQueue?.runJob({ aaa: 1, bbb: 2 }, { delay: 1000 });
    // // 更新进度
    // await job.progress(60);
    // // 获取进度 
    // const progress = await job.progress();
    // console.log(progress);
    // const state = await job.getState();
    // console.log(state);


  }
}

